package com.haizhi.script;

import com.dinstone.beanstalkc.BeanstalkClient;
import com.haizhi.beanstalk.BeanstalkFactory;
import com.haizhi.util.JsonUtil;
import com.haizhi.util.PropertyUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: youfeng
 * Date: 2018-06-25
 * Time: 20:54
 */
public class ProducerReport {
    private static final Logger logger = LogManager.getLogger(ProducerReport.class);

    static {
        //先装载配置信息
        PropertyUtil.loadProperties("beanstalk/consumer.properties");
    }

    public static void main(String... args) {
        //消息队列句柄

        //获取消费者
        BeanstalkClient producer = BeanstalkFactory.getProducer(PropertyUtil.getProperty("beanstalk.host"),
                PropertyUtil.getInt("beanstalk.port"),
                PropertyUtil.getProperty("beanstalk.tube"));


        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("company", "深圳前海致云投资管理有限公司");
        dataMap.put("province", "guangdong");
        dataMap.put("crawl_status", 0);
        dataMap.put("search_status", 0);

        String dataStr = JsonUtil.objectToJson(dataMap);
        if (null != dataStr) {
            BeanstalkFactory.put(producer, dataStr);

        }

        logger.info("发送数目: province = {} count = {}", "beijing", 1);

//        for (Province province : Province.values()) {
//            for (int i = 0; i < 1000; i++) {
//                Map<String, String> dataMap = new HashMap<>();
//                dataMap.put("company", "海之科技有限公司" + i);
//                dataMap.put("source_url", "bigdata.com");
//                dataMap.put("province", province.getValue());
//
//                String dataStr = JsonUtil.objectToJson(dataMap);
//                beanstalkHandler.put(producer, dataStr);
//
//                logger.info("发送数目: province = {} count = {}", province.getValue(), i);
//            }
//        }


        producer.close();
    }
}
